﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Google.GData.Client;
using Google.Contacts;

namespace GoogleContactSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            RequestSettings settings = new RequestSettings(
                "x-pim-dev", "x.pim.dev@gmail.com", "P@$$w0rd2218");
            settings.AutoPaging = true;
            //settings.PageSize = int.MaxValue;
            ContactsRequest request = new ContactsRequest(settings);

            Feed<Contact> contacts = request.GetContacts();
            List<Object> list = new List<object>();
            foreach (Contact c in contacts.Entries)
            {
                list.Add(new
                {
                    c.Name.FullName,
                    Email = c.PrimaryEmail != null ? c.PrimaryEmail.Address : "",
                    Phone = c.PrimaryPhonenumber != null ? c.PrimaryPhonenumber.Value : "",
                });
            }
            lstContacts.DataSource = list;
        }
    }
}
